﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;

namespace SimplexEngine
{
    public class TextureRenderContext : RenderContext
    {
        protected RenderTarget2D color_render_target = null;

        public TextureRenderContext(String context_name, RenderSystem creator) : base(context_name, creator)
        {
            name = context_name;

            // get presentation parameters
            PresentationParameters presentation_parameters = Root.Instance.RenderSystem.GraphicsDevice.PresentationParameters;
            // create render targets
            color_render_target = new RenderTarget2D(Root.Instance.RenderSystem.GraphicsDevice, presentation_parameters.BackBufferWidth, presentation_parameters.BackBufferHeight, 1, presentation_parameters.BackBufferFormat);

            render_targets.Add(color_render_target);
            render_target_map.Add(name, color_render_target);
        }

        protected String texture_name = "";

        protected List<RenderTarget2D> render_targets = new List<RenderTarget2D>();
        protected Dictionary<String, RenderTarget2D> render_target_map = new Dictionary<String, RenderTarget2D>();

        protected internal override List<RenderTarget2D> GetRenderTargets()
        {
            return render_targets;
        }

        protected override void OnDraw(GameTime game_time, Int64 frame_number)
        {
            base.OnDraw(game_time, frame_number);
        }

        protected internal override List<String>  GetTextureNames()
        {
 	        return render_target_map.Keys.ToList();
        }

        protected internal override Texture2D GetTexture(String name)
        {
            RenderTarget2D render_target = null;

            render_target_map.TryGetValue(name, out render_target);

            return render_target == null ? null : render_target.GetTexture();
        }
    }
}
